home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / docs / Var_Dump / example-3.php < prev    next >
PHP Script  |  2004-10-01  |  3KB  |  111 lines

  1. <?php
  2.  
  3. include_once 'Var_Dump.php';
  4.  
  5. echo '<h1>example3.php : factory approach</h1>';
  6.  
  7. /*
  8.  * example3.php : Factory approach
  9.  *
  10.  * If you want to use a factory object, you will have to instanciate an
  11.  * object with the appropriate parameters, and then to use the "toString"
  12.  * method, as the display method is inacurate in this case.
  13.  *
  14.  */
  15.  
  16. // Initialise the HTML4 Table rendering (see Var_Dump/Renderer/HTML4_Table.php)
  17. $myVarDump = & Var_Dump::factory(
  18.     array(
  19.         'display_mode' => 'HTML4_Table'
  20.     ),
  21.     array(
  22.         'show_caption'   => FALSE,
  23.         'bordercolor'    => '#DDDDDD',
  24.         'bordersize'     => '2',
  25.         'captioncolor'   => 'white',
  26.         'cellpadding'    => '4',
  27.         'cellspacing'    => '0',
  28.         'color1'         => '#FFFFFF',
  29.         'color2'         => '#F4F4F4',
  30.         'before_num_key' => '<font color="#CC5450"><b>',
  31.         'after_num_key'  => '</b></font>',
  32.         'before_str_key' => '<font color="#5450CC">',
  33.         'after_str_key'  => '</font>',
  34.         'before_value'   => '<i>',
  35.         'after_value'    => '</i>'
  36.     )
  37. );
  38.  
  39. /*
  40.  * Displays an array
  41.  */
  42.  
  43. echo '<h2>Array</h2>';
  44.  
  45. $fileHandler=tmpfile();
  46. $linkedArray=array('John', 'Jack', 'Bill');
  47. $array=array(
  48.     'key-1' => 'The quick brown fox jumped over the lazy dog',
  49.     'key-2' => 234,
  50.     'key-3' => array(
  51.         'key-3-1' => 31.789,
  52.         'key-3-2' => & $linkedArray,
  53.         'file'    => $fileHandler
  54.     ),
  55.     'key-4' => NULL
  56. );
  57. echo $myVarDump->toString($array);
  58.  
  59. /*
  60.  * Displays an object (with recursion)
  61.  */
  62.  
  63. echo '<h2>Object (Recursive)</h2>';
  64.  
  65. class parent {
  66.     function parent() {
  67.         $this->myChild = new child($this);
  68.         $this->myName = 'parent';
  69.     }
  70. }
  71. class child {
  72.     function child(&$parent) {
  73.         $this->myParent =& $parent;
  74.     }
  75. }
  76. $recursiveObject=new parent();
  77. echo $myVarDump->toString($recursiveObject);
  78.  
  79. /*
  80.  * Displays a classic object
  81.  */
  82.  
  83. echo '<h2>Object (Classic)</h2>';
  84.  
  85. class test {
  86.     var $foo=0;
  87.     var $bar="";
  88.     function get_foo() {
  89.         return $this->foo;
  90.     }
  91.     function get_bar() {
  92.         return $this->bar;
  93.     }
  94. }
  95. $object=new test();
  96. $object->foo=753;
  97. $object->bar="357";
  98. echo $myVarDump->toString($object);
  99.  
  100. /*
  101.  * Displays a variable using the display() method
  102.  */
  103.  
  104. echo '<h2>Var_Dump::display()</h2>';
  105. echo '<p>Singleton method, uses the default configuration parameters for the rendering, because we are not using the previously instanciated object</p>';
  106.  
  107. Var_Dump::display($array);
  108.  
  109. fclose($fileHandler);
  110.  
  111. ?>